import {Component, OnDestroy, OnInit} from '@angular/core';
import {Subscription} from 'rxjs/Subscription';
import {Page} from '../../admin/admin-breadcrumb/breadcrumb';
import {PageSubject} from '../../../util/page-subject';
import {LogUtil} from '../../../util/log-util';

@Component({
  selector: 'app-datav-breadcrumb',
  templateUrl: './datav-breadcrumb.component.html',
  styleUrls: ['./datav-breadcrumb.component.css']
})
export class DatavBreadcrumbComponent implements OnInit, OnDestroy {

  private subscription: Subscription;
  breadCrumb: Page;

  constructor(
    private pageSubject: PageSubject,
    private logUtil: LogUtil
  ) {
  }

  ngOnInit() {
    this.logUtil.debug('page订阅');
    this.subscribePage();
  }

  private subscribePage() {
    this.subscription = this.pageSubject.subscribePage().subscribe(
      (page: Page) => {
        if (!!page) {
          this.logUtil.debug('当前页：' + JSON.stringify(page));
          this.breadCrumb = new Page(page.homePageName, page.homePageUrl, page.curPageName, page.curOperName, page.paths);
        }
      }
    );
  }

  ngOnDestroy() {
    this.subscription.unsubscribe();
  }

}
